package com.googlecode.hessianserver.example.spring;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Creates a new <code>HessianServer</code> managed by spring
 *
 * @author rayvanderborght
 */
public class ExampleSpringServer
{
	private AbstractApplicationContext context;

	/**
	 * Startup <code>HessianServer</code> inside a spring container
	 */
	public void startSpring()
	{
		this.context = new ClassPathXmlApplicationContext(new String[] { "services.xml" });
	}

	/**
	 * Shutdown the spring container (and <code>HessianServer</code> along with it)
	 */
	public void shutdownSpring()
	{
		this.context.close();
	}

	/**
	 * Demonstrates <code>HessianServer</code> running inside of spring
	 * 
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception
	{
		ExampleSpringServer exampleSpringServer = new ExampleSpringServer();

		exampleSpringServer.startSpring();

		System.out.println("ExampleSpringServer started. Use 'x' to quit");
		while (System.in.read() != 'x')
		{
			// keep reading until 'x' is entered
		}

		exampleSpringServer.shutdownSpring();
	}
}
